package com.boot.main.controller;

import com.boot.main.entity.ScomShopCart;
import com.boot.main.service.IShopCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/v1/api")
@Api(tags = "购物车管理")
public class ShopCartController {
    @Resource
    private IShopCartService shopCartService;

    @RequestMapping(value="/shopCarts", method = RequestMethod.GET)
    @ApiOperation(value="获取购物车列表")
    public Object getShopCarts(){
        return shopCartService.getShopCarts();
    }

    @RequestMapping(value="/shopCart", method = RequestMethod.POST)
    @ApiOperation(value="新增购物车")
    public Object saveShopCart(@RequestBody ScomShopCart shopCart){
        return shopCartService.saveShopCart(shopCart);
    }

    @RequestMapping(value="/shopCart/{id}", method = RequestMethod.POST)
    @ApiOperation(value="新增购物车")
    public Object updateShopCart(@RequestBody Map map, @PathVariable("id") Long id){
        Integer num = Integer.parseInt(map.get("num").toString());
        return shopCartService.updateShopCart(id, num);
    }

    @RequestMapping(value="/shopCart/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除购物车")
    public Object deleteShopCart(@PathVariable Long id){
        return shopCartService.deleteShopCart(id);
    }
}
